package com.xu.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xudenghui
 * @create 2021-12-28 13:34
 **/
@RestController
public class FlowLimitController {


    @GetMapping("/testA")
    public String testA()
    {
        return "------testA";
    }

    @GetMapping("/testB")
    public String testB()
    {
        return "------testB";
    }


    /**
     * 限流报错
     * @return
     */
//    @SentinelResource(value = "hello",blockHandler = "blockHandlerHello")
    @GetMapping("/say")
    public String hello(){
        return  "hello,xu deng hui";
    }

    public String blockHandlerHello(BlockException e){
        return "被限流了!";
    }


    /**
     *提供了一个携带{id}参数的Rest风格Api sentinel把所有url当做资源来管控
     * 导致问题：
     *    1：限流统计不准确 实际需求是控制clean方法总的QPS 结果统计的是每个URL的QPS
     *    2：导致Sentinel中资源数量过多，默认资源数据的阈值是6000 对于多出的资源规则将不会生效
     * @param id
     * @return
     * @link  CustomerUrlCleaner 处理方法 实现URLCleaner接口 并重写clean方法即可
     */
    @GetMapping("/clean/{id}")
    public String clean(@PathVariable("id")String id){
        return  "Hello clean"+id;
    }


}
